﻿#include "updateinfo.h"
#include "ui_updateinfo.h"
#include "qpainter.h"
#include "DataBase/mysql.h"
#include "constant.h"

#include <qthread.h>
UpdateInfo::UpdateInfo(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::UpdateInfo)
{
    ui->setupUi(this);
    setWindowFlags(Qt::Tool |Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint|Qt::Dialog);
    setWindowModality(Qt::ApplicationModal);
}

UpdateInfo::~UpdateInfo()
{
    delete ui;
}
void UpdateInfo::getUserID(QString userid)
{
    QString file=Constant::DataBasePath;
    Qt::HANDLE threadId = QThread::currentThreadId();
    QString threadIdStr = QString::number(reinterpret_cast<quintptr>(threadId));

    MySql *mySql = new MySql(file,threadIdStr);
    UserInfoBean uib;
    mySql->MySelect(userid,uib);
    ui->Regist_UserID->setText(userid);
    ui->Regist_UserID->setEnabled(false);
    ui->Regist_UserName->setText(uib.UserName);
    ui->Regist_UserPwd->setText(uib.UserPwd);
    ui->Regist_UserAge->setText(uib.UserAge);
    if(uib.UserSex=="男")
        ui->Regist_radioButton_Male->setChecked(true);
    else
        ui->Regist_radioButton_Female->setChecked(true);
    delete  mySql;

}
void UpdateInfo::paintEvent(QPaintEvent *event)
{
    //通过这种方式可以将图片平铺到窗口上
    //使用样式表可以很方便设置界面，而且非常高效，还能让界面和逻辑分离
    //不过在本例中由于是顶层窗口，所以直接设置样式表也不会显示。
    //所以样式表比较适合子窗口来使用。
    QPainter painter(this);
    painter.drawPixmap(rect(),QPixmap(":/images/share/js_bg.png"),QRect());
}

void UpdateInfo::on_pushButton_exit_clicked()
{
    close();
}

void UpdateInfo::on_Regist_pb_OK_clicked()
{
    QString file=Constant::DataBasePath;
    Qt::HANDLE threadId = QThread::currentThreadId();
    QString threadIdStr = QString::number(reinterpret_cast<quintptr>(threadId));

    MySql *mySql = new MySql(file,threadIdStr);
    UserInfoBean uib;
    uib.UserID=ui->Regist_UserID->text();
    uib.UserName=ui->Regist_UserName->text();
    uib.UserAge=ui->Regist_UserAge->text();
    uib.UserPwd=ui->Regist_UserPwd->text();
    if(ui->Regist_radioButton_Male->isChecked())
        uib.UserSex="男";
    else
        uib.UserSex="女";
    sendUpdateSucess(mySql->MyUpdate(uib));
    delete mySql;
    close();
}

void UpdateInfo::on_Regist_pb_Return_clicked()
{
    close();
}
